<template>
  <el-form label-width="100px" class="cont">
    <el-form-item label="密码">
      <el-input
        type="password"
        v-model="password"
        placeholder="请输入新密码..."
      ></el-input>
    </el-form-item>
    <el-form-item>
      <el-button
        type="primary"
        @click="handleResetPassword()"
        class="submit-btn"
        >重置密码
      </el-button>
    </el-form-item>
  </el-form>
</template>

<script lang="ts">
import { ref, getCurrentInstance } from "vue";
import { useRouter, useRoute } from "vue-router";

export default {
  name: "ResetPassword",
  props: {},
  setup() {
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    const { ctx } = getCurrentInstance();

    const password = ref<string>("");
    const route = useRoute();
    const router = useRouter();

    const handleResetPassword = async () => {
      if (password.value) {
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
        const res = await ctx.$axios.post(
          "/api/v1/auth/resetpassword/" + route.params.id,
          {
            password: password.value,
          }
        );
        if (res.data.success) {
          router.push("/");
        }
      }
    };

    return { handleResetPassword, password };
  },
};
</script>
